#ifndef  __OBSERVER_H
#define  __OBSERVER_H

#define   	_iq							signed int 
	
#define		_IQ15(x)					(u16)((x)*32767)
#define		_IQmpy(x,y) 				(((x)*(y))>>15)
#define 	_IQabs(Value)			 	((Value)>=0?(Value):-(Value))
#define		_IQdiv(x,y)					(HWDIV_Div((x),(y)))



typedef struct 
{  
	_iq  Valpha;    // Input: Stationary alfa-axis stator voltage 
 
	_iq  Ealpha;   // Variable: Stationary alfa-axis back EMF 

	_iq  Zalpha;      // Output: Stationary alfa-axis sliding control 

	_iq  Gsmopos;    // Parameter: Motor dependent control gain 

	_iq  EstIalpha;   // Variable: Estimated stationary alfaaxis stator current 

	_iq  Fsmopos;    // Parameter: Motor dependent plant matrix 

	_iq  Vbeta;    // Input: Stationary beta-axis stator voltage 

	_iq  Ebeta;   // Variable: Stationary beta-axis back EMF 

	_iq  Zbeta;      // Output: Stationary beta-axis sliding control 

	_iq  EstIbeta;    // Variable: Estimated stationary beta-axis statorcurrent 

	_iq  Ialpha;   // Input: Stationary alfa-axis stator current 

	_iq  IalphaError; // Variable: Stationary alfaaxis current error                 

	_iq  Kslide;     // Parameter: Sliding control gain 

	_iq  Ibeta;   // Input: Stationary beta-axis stator current 

	_iq  IbetaError;  // Variable: Stationary betaaxis current error                 

	_iq  Kslf;       // Parameter: Sliding control filter gain 

	_iq  Theta;     // Output: Compensated rotor angle 
	
	_iq  ThetaRamp;     // Output: Compensated rotor angle 
	
	_iq  DeltaTheta;     // Output: DeltaTheta	
	
	_iq  We;     // Output: Compensated rotor we
	
	_iq  We_Limit;     // Output: Compensated rotor we
	
	_iq  E0;     // Output: Compensated rotor angle 
 
 
} T_SMO;             
 
 
extern T_SMO		t_Obse; 
extern void 		Observer_Calc(T_SMO *v);
extern void 		Observer_Init(T_SMO *v);
extern void			BasePara_Init(void);
extern void 		ROT_Theta_Calc(T_SMO *E);
extern signed int 	Get_RotElec_Angle(void);

#endif
 

